<template>
  <el-card>
    <div class="box">
      <h1>个人信息</h1>
      <el-form :model="msgParams" ref="msgParams">
        <el-row :gutter="24">
          <el-form-item label="账号：" prop="username">
            <el-input
              type="text"
              v-model="msgParams.username"
              :disabled="Flag"
            />
          </el-form-item>
        </el-row>
        <el-row :gutter="24">
          <el-form-item label="姓名：" prop="name">
            <el-input type="text" v-model="msgParams.name" :disabled="Flag" />
          </el-form-item>
        </el-row>
        <el-row :gutter="24">
          <el-form-item label="电话：" prop="telephone">
            <el-input
              type="text"
              v-model="msgParams.telephone"
              :disabled="DisabledFlag"
            />
          </el-form-item>
        </el-row>
        <el-row :gutter="24">
          <el-form-item label="邮箱：" prop="email">
            <el-input
              type="text"
              v-model="msgParams.email"
              :disabled="DisabledFlag"
            />
          </el-form-item>
        </el-row>
        <el-row :gutter="24">
          <el-form-item label="地址：" prop="address">
            <el-input
              type="text"
              v-model="msgParams.address"
              :disabled="DisabledFlag"
            />
          </el-form-item>
        </el-row>
        <el-row :gutter="24">
          <el-form-item>
            <el-button
              v-if="DisabledFlag == true"
              :type="DisabledFlag == true ? 'primary' : 'success'"
              id="box_button"
              @click="this.DisabledFlag = false"
              >{{ DisabledFlag == true ? "编辑" : "保存" }}</el-button
            >
            <el-button
              v-else
              :type="DisabledFlag == true ? 'primary' : 'success'"
              id="box_button"
              @click="UpdatePerInfo()"
              >{{ DisabledFlag == true ? "编辑" : "保存" }}</el-button
            >
          </el-form-item>
        </el-row>
      </el-form>
    </div>
  </el-card>
</template>
<script>
import { FindInfo, updateMsg } from "@/api/login";
export default {
  data() {
    return {
      Flag: true,
      DisabledFlag: true,
      msgParams: {
        username: "",
        name: "",
        telephone: "",
        email: "",
        address: "",
      },
    };
  },
  created() {
    this.username = localStorage.getItem("username");
    this.queryInfo();
  },
  methods: {
    queryInfo() {
      FindInfo(this.username).then((res) => {
        this.msgParams = res.data.data;
      });
    },
    UpdatePerInfo() {
      updateMsg(this.msgParams).then((res) => {
        if (res.data.code == 200) {
          this.DisabledFlag = true;
          this.queryInfo();
        }
      });
    },
  },
};
</script>
<style>
.el-form-item__label {
  width: 85px !important;
  /* border: 1px solid red !important; */
}
</style>
<style lang="scss" scoped>
.box {
  width: 100%;
  height: 75vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  h1 {
    margin-bottom: 30px;
    font-weight: 600;
    font-size: 18px;
  }
  #box_button {
    margin-left: 230px;
  }
}
</style>
